package com.liuzhilong.infrastructure.framework.spring.processor;

import com.liuzhilong.infrastructure.framework.spring.component.UnMarkComponet;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class TestBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor  {
    /**
     * 把{@link com.liuzhilong.infrastructure.framework.spring.component.UnMarkComponet}注册到容器中
     * @param registry
     * @throws BeansException
     */
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        //不知道怎么构建BeanDefinition的话建议使用BeanDefinitionBuilder进行构建
        BeanDefinition beanDefinition=  BeanDefinitionBuilder.genericBeanDefinition(UnMarkComponet.class).setScope(BeanDefinition.SCOPE_SINGLETON).getBeanDefinition();
        registry.registerBeanDefinition("com.liuzhilong.infrastructure.framework.spring.component.UnMarkComponet",beanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            //DO NOTHING
    }
}
